home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-11 / vs_804.zip / ERRORSYS.PRG < prev    next >
Text File  |  1991-12-03  |  10KB  |  288 lines

  1. * Filename......: ErrorSys.Prg
  2. *
  3. * Author........: Vernon E. Six, Jr.
  4. *
  5. * Last Update...: Tue  12-03-1991  12:13:59
  6. *
  7. * Notice........: Copyright (c) 1991 by Vernon E. Six, Jr.
  8. *                 All Rights Reserved World Wide
  9. *
  10. * Dialect.......: Clipper v5.01
  11. *
  12. * Compile as....: Clipper ErrorSys /n/w/b/a
  13.  
  14.  
  15. #include "SETCURS.CH"
  16. #include "INKEY.CH"
  17. #include "ERROR.CH"
  18. #include "FILEIO.CH"
  19. #include "VERNSIX.CH"
  20.  
  21. *******************
  22.  
  23. PROCEDURE ErrorSys
  24.  
  25.    Errorblock( { | o_Error | LogError(o_Error) } )
  26.  
  27. *******************
  28.  
  29. STATIC FUNCTION LogError( o_Error )
  30. *****
  31. * Log errors to disk
  32. *****               
  33. LOCAL c_FileName   := "Error.Log"
  34. LOCAL c_OutStr
  35. LOCAL c_Screen     := SaveScreen( 0, 0, MaxRow(), MaxCol() )
  36. LOCAL c_SubStr
  37. LOCAL n_Cntr
  38. LOCAL n_Handle
  39. LOCAL n_Range
  40. LOCAL n_Start
  41. LOCAL x, y, i
  42.  
  43.  
  44.    //
  45.    // by default, division by zero is zero
  46.    //
  47.    IF ( o_Error:genCode == EG_ZERODIV )
  48.  
  49.       RETURN(0)
  50.  
  51.    ENDIF
  52.  
  53.  
  54.  
  55.    //
  56.    // for network open error, set NETERR() and subsystem default
  57.    //
  58.    IF ( o_Error:genCode    == EG_OPEN .AND. ;
  59.         o_Error:osCode     == 32      .AND. ;
  60.         o_Error:canDefault                    )
  61.  
  62.        NetErr(.T.)
  63.        RETURN(.F.)
  64.  
  65.    ENDIF
  66.  
  67.  
  68.  
  69.    //
  70.    // for lock error during APPEND BLANK, set NETERR() and subsystem default
  71.    //
  72.    IF ( o_Error:genCode == EG_APPENDLOCK .AND. o_Error:canDefault )
  73.  
  74.        NetErr(.T.)
  75.        RETURN(.F.)
  76.  
  77.    ENDIF
  78.  
  79.  
  80.  
  81.    //
  82.    // Let the user know that something has hit the fan
  83.    //
  84.    VS_Alert( {"","A serious error has occurred.  Please check " + ;
  85.              c_FileName,""}, {" Ok "}, 3 )
  86.  
  87.  
  88.  
  89.    //
  90.    // Append to the file if it already exists, otherwise create a new one
  91.    //
  92.    IF .NOT. FILE(c_FileName)
  93.       n_Handle := FCREATE( c_FileName, FC_NORMAL )
  94.     ELSE
  95.       n_Handle := FOPEN(   c_FileName, FO_READWRITE + FO_EXCLUSIVE )
  96.    ENDIF
  97.  
  98.  
  99.  
  100.    //
  101.    // Scream and holler if the file could not be opened!
  102.    //
  103.    IF FERROR() != 0
  104.  
  105.       VS_NewScrn()
  106.       VS_Alert( {"",PADC("Due to an error, information was not",40), ;
  107.                     PADC("written to "+c_FileName,40), "" }, ;
  108.                 { " Ok " }, 3 )
  109.  
  110.     ELSE
  111.  
  112.       //
  113.       // Go to the end of the file
  114.       //
  115.       FSEEK( n_Handle, 0, FS_END )
  116.  
  117.       FWriteLine( n_Handle, PADR("═══ Error Log File ", 79, "═" )           )
  118.       FWriteLine( n_Handle, ""                                              )
  119.       FWriteLine( n_Handle, "Error Occurred In: " + PROCNAME(2)             )
  120.       FWriteLine( n_Handle, ""                                              )
  121.       FWriteLine( n_Handle, ""                                              )
  122.       FWriteLine( n_Handle, "             Date: " + DTOC( DATE() )          )
  123.       FWriteLine( n_Handle, "             Time: " + TIME()                  )
  124.       FWriteLine( n_Handle, " Available Memory: " + VS_Cvt2Str( MEMORY(0) ) )
  125.       FWriteLine( n_Handle, "     Current Area: " + VS_Cvt2Str( SELECT()  ) )
  126.                                                                             
  127.  
  128.       FWriteLine( n_Handle, ""                                                          )
  129.       FWriteLine( n_Handle, PADR( "─── Internal Error Handling Information ", 79, "─" ) )
  130.       FWriteLine( n_Handle, ""                                                          )
  131.       FWriteLine( n_Handle, "Clipper Error#: " + VS_Cvt2Str( o_Error:genCode    )       )
  132.       FWriteLine( n_Handle, "Subsystem call: " + o_Error:subsystem                      )
  133.       FWriteLine( n_Handle, "   System code: " + VS_Cvt2Str( o_Error:subcode    )       )
  134.       FWriteLine( n_Handle, "Default Status: " + VS_Cvt2Str( o_Error:candefault )       )
  135.       FWriteLine( n_Handle, "      Filename: " + o_Error:filename                       )
  136.       FWriteLine( n_Handle, "   Description: " + o_Error:description                    )
  137.       FWriteLine( n_Handle, "     Operation: " + o_Error:operation                      )
  138.       FWriteLine( n_Handle, "DOS Error Code: " + VS_Cvt2Str( o_Error:oscode     )       )
  139.       FWrite(     n_Handle, " Trace Through: "                                          )
  140.  
  141.       x := 1
  142.       DO WHILE !EMPTY( PROCNAME(++x) )
  143.  
  144.          FWriteLine( n_Handle, PADR(PROCNAME(x), 20) + ": " + ;
  145.                                PADR(PROCLINE(x), 20) )
  146.                                
  147.          FWrite( n_Handle, SPACE(16) )
  148.  
  149.       ENDDO
  150.       FWrite( n_Handle, CHR(13)+CHR(10) )
  151.       
  152.  
  153.  
  154.       *══════════════════════════════════════════════════════════*
  155.  
  156.       IF VALTYPE( o_Error:args ) == "A"
  157.  
  158.          FWrite(     n_Handle, "     Arguments: "                                          )
  159.          FOR x = 1 TO LEN( o_Error:args )
  160.  
  161.             FWriteLine( n_Handle, STRZERO(x,3) + ": " + VS_Cvt2Str( o_Error:args[x] )      )
  162.  
  163.          NEXT x
  164.          FWrite( n_Handle, CHR(13)+CHR(10) )
  165.  
  166.       ENDIF
  167.  
  168.  
  169.       *══════════════════════════════════════════════════════════*
  170.  
  171.       FWriteLine( n_Handle, "" )
  172.       FWriteLine( n_Handle, "" )
  173.       FWriteLine( n_Handle, "┌"+PADR("─── Video Screen Dump ",80,"─")+"┐" )
  174.  
  175.       n_Start := 1
  176.       n_Range := (MAXCOL()+1)*2
  177.  
  178.       FOR x = 1 TO MAXROW()
  179.  
  180.          c_SubStr := SUBSTR(c_Screen, n_Start, n_Range )
  181.  
  182.          FWrite( n_Handle, "│" )
  183.  
  184.          FOR y = 1 to n_Range STEP 2
  185.  
  186.             FWrite( n_Handle, SUBSTR(c_SubStr, y, 1) )
  187.  
  188.          NEXT
  189.  
  190.          FWriteLine( n_Handle, "│" )
  191.  
  192.          n_Start += n_Range
  193.  
  194.       NEXT
  195.  
  196.       FWriteLine( n_Handle, "└"+REPLICATE("─",79)+"┘" )
  197.  
  198.  
  199.  
  200.       *══════════════════════════════════════════════════════════*
  201.       
  202.       FWriteLine( n_Handle, "" )
  203.       FWriteLine( n_Handle, "" )
  204.       FWriteLine( n_Handle, PADR( "─── Detailed Work Area Items ", 79, "─" ) )
  205.       FWriteLine( n_Handle, "" )
  206.  
  207.       FOR n_Cntr = 1 TO 250
  208.  
  209.          IF !EMPTY( ALIAS(n_Cntr) )
  210.  
  211.             SELECT( n_Cntr )
  212.  
  213.             FWriteLine( n_Handle, "   Work Area No.: " + VS_Cvt2Str( SELECT()   )           )
  214.             FWriteLine( n_Handle, "      Alias Name: " + ALIAS()                            )
  215.             FWriteLine( n_Handle, "  Current Recno.: " + VS_Cvt2Str( RECNO()    )           )
  216.             FWriteLine( n_Handle, "  Current Filter: " + dbFilter()                         )
  217.             FWriteLine( n_Handle, "   Relation Exp.: " + dbRelation()                       )
  218.             FWriteLine( n_Handle, "     Index Order: " + VS_Cvt2Str( INDEXORD() )           )
  219.             FWriteLine( n_Handle, "      Active Key: " + INDEXKEY( INDEXORD() )             )
  220.             
  221.             FWriteLine( n_Handle, "" )
  222.             FWriteLine( n_Handle, "Current Record..." )
  223.             FWriteLine( n_Handle, "" )
  224.  
  225.             FOR i = 1 TO FCOUNT()
  226.                FWriteLine( n_Handle, PADR(FieldName(i),14) + ": " + VS_Cvt2Str( FieldGet(i) ) )
  227.             NEXT i
  228.  
  229.             FWriteLine( n_Handle, "" )
  230.             FWriteLine( n_Handle, "" )
  231.             
  232.  
  233.          ENDIF
  234.  
  235.       NEXT n_Cntr
  236.  
  237.  
  238.       FWriteLine( n_Handle, PADC( " Environmental Information ", 79, "-" )               )
  239.       FWriteLine( n_Handle, ""                                                           )
  240.       FWriteLine( n_Handle, "      Exact is: " + VS_Cvt2Str( SET(_SET_EXACT     ), .T. ) )
  241.       FWriteLine( n_Handle, "      Fixed is: " + VS_Cvt2Str( SET(_SET_FIXED     ), .T. ) )
  242.       FWriteLine( n_Handle, "Decimals is at: " + VS_Cvt2Str( SET(_SET_DECIMALS  )      ) )
  243.       FWriteLine( n_Handle, "Path is set to: " + VS_Cvt2Str( SET(_SET_PATH      )      ) )
  244.       FWriteLine( n_Handle, " Default is at: " + VS_Cvt2Str( SET(_SET_DEFAULT   )      ) )
  245.       FWriteLine( n_Handle, "      Epoch is: " + VS_Cvt2Str( SET(_SET_EPOCH     )      ) )
  246.       FWriteLine( n_Handle, "Date Format at: " + VS_Cvt2Str( SET(_SET_DATEFORMAT)      ) )
  247.       FWriteLine( n_Handle, "  Alternate is: " + VS_Cvt2Str( SET(_SET_ALTERNATE ), .T. ) )
  248.       FWriteLine( n_Handle, " Alter File is: " + VS_Cvt2Str( SET(_SET_ALTFILE   )      ) )
  249.       FWriteLine( n_Handle, "    Console is: " + VS_Cvt2Str( SET(_SET_CONSOLE   ), .T. ) )
  250.       FWriteLine( n_Handle, " Margin is set: " + VS_Cvt2Str( SET(_SET_MARGIN    )      ) )
  251.       FWriteLine( n_Handle, "    Printer is: " + VS_Cvt2Str( SET(_SET_PRINTER   ), .T. ) )
  252.       FWriteLine( n_Handle, "  Printer File: " + VS_Cvt2Str( SET(_SET_PRINTFILE )      ) )
  253.       FWriteLine( n_Handle, "  Device is at: " + VS_Cvt2Str( SET(_SET_DEVICE    )      ) )
  254.       FWriteLine( n_Handle, "       Bell is: " + VS_Cvt2Str( SET(_SET_BELL      ), .T. ) )
  255.       FWriteLine( n_Handle, "    Confirm is: " + VS_Cvt2Str( SET(_SET_CONFIRM   ), .T. ) )
  256.       FWriteLine( n_Handle, "Delimiters are: " + VS_Cvt2Str( SET(_SET_DELIMITERS), .T. ) )
  257.       FWriteLine( n_Handle, " Delimit Chars: " + VS_Cvt2Str( SET(_SET_DELIMCHARS)      ) )
  258.       FWriteLine( n_Handle, " Escape is set: " + VS_Cvt2Str( SET(_SET_ESCAPE    ), .T. ) )
  259.       FWriteLine( n_Handle, "  Intensity is: " + VS_Cvt2Str( SET(_SET_INTENSITY ), .T. ) )
  260.       FWriteLine( n_Handle, " Scoreboard is: " + VS_Cvt2Str( SET(_SET_SCOREBOARD), .T. ) )
  261.       FWriteLine( n_Handle, "   Wrap is set: " + VS_Cvt2Str( SET(_SET_WRAP      ), .T. ) )
  262.       FWriteLine( n_Handle, "  Message Line: " + VS_Cvt2Str( SET(_SET_MESSAGE   )      ) )
  263.       FWriteLine( n_Handle, "Message Center: " + VS_Cvt2Str( SET(_SET_MCENTER   ), .T. ) )
  264.       FWriteLine( n_Handle, "  Exclusive is: " + VS_Cvt2Str( SET(_SET_EXCLUSIVE ), .T. ) )
  265.       FWriteLine( n_Handle, "   Softseek is: " + VS_Cvt2Str( SET(_SET_SOFTSEEK  ), .T. ) )
  266.       FWriteLine( n_Handle, "     Unique is: " + VS_Cvt2Str( SET(_SET_UNIQUE    ), .T. ) )
  267.       FWriteLine( n_Handle, "    Deleted is: " + VS_Cvt2Str( SET(_SET_DELETED   ), .T. ) )
  268.  
  269.  
  270.       FWriteLine( n_Handle, "" )
  271.  
  272.       FCLOSE( n_Handle )
  273.  
  274.    ENDIF
  275.  
  276.    ERRORLEVEL( 1 )
  277.    CLEAR SCREEN
  278.    
  279.    dbCloseAll()
  280.    QUIT
  281.  
  282. RETURN( .F. )
  283.  
  284. *** EOF: LogError() *********************************************************
  285.  
  286.  
  287.  
  288.